package com.naihe.anderson.sms.dbhelper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.naihe.anderson.sms.entity.Note;

public class NoteDBHelper extends SQLiteOpenHelper {

	private static final int DEFAULT_VERSION = 1;
	private static final String DB_NAME_PREFIX = "note_db";
	public static final String NOTE_TABLE_NAME = "note";
	
	public final static String[] note_projection = {
		Note._ID,
		Note.BODY,
		Note.CIPHER,
		Note.TITLE,
		Note.CREATE_TIME,
		Note.PICPATH
	};
	
	private final static String NOTE_TABLE_CREATE  = "CREATE TABLE IF NOT EXISTS "
			+ NOTE_TABLE_NAME
			+ "("
			+ Note._ID 						+ " INTEGER PRIMARY KEY,"
			+ Note.BODY			 			+ " TEXT,"
			+ Note.CIPHER 					+ " TEXT,"
			+ Note.TITLE 					+ " TEXT,"
			+ Note.PICPATH 					+ " TEXT,"
			+ Note.CREATE_TIME 				+ " INTEGER"
			+");";
	
	public NoteDBHelper(Context context) {
		super(context, DB_NAME_PREFIX+".db", null, DEFAULT_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(NOTE_TABLE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

	public SQLiteDatabase openForWrite(String name)  throws Exception{ 
		return getWritableDatabase();
	}

	public SQLiteDatabase openForRead(String name) throws Exception{
		return getReadableDatabase();
	}
	
}
